/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.infomatik.tundra.logic.security;

import java.util.List;

import edu.infomatik.tundra.data.DAOtundra;
import edu.infomatik.tundra.data.IBean;
import edu.infomatik.tundra.util.TundraConstants;


/**
 * <!-- begin-user-doc -->
 * A representation of the model object '<em><b>System Access</b></em>'.
 * <!-- end-user-doc -->
 *
 * <p>
 * The following features are supported:
 * <ul>
 *   <li>{@link edu.infomatik.tundra.MockSystemAccessBean.SystemAccess#getUserName <em>User Name</em>}</li>
 *   <li>{@link edu.infomatik.tundra.MockSystemAccessBean.SystemAccess#getPassword <em>Password</em>}</li>
 *   <li>{@link edu.infomatik.tundra.MockSystemAccessBean.SystemAccess#getUserType <em>User Type</em>}</li>
 *   <li>{@link edu.infomatik.tundra.MockSystemAccessBean.SystemAccess#getNewUser <em>new User</em>}</li>
 * </ul>
 * </p>
 *
 * @model
 * @generated
 */
public class SystemAccessBean implements IBean{
	private UserTypes DEFAULT_USER_TYPE = UserTypes.EXTERN;
	private long id;
	private String userName;
	private String password;
	private String eMail;
	private UserTypes userType = DEFAULT_USER_TYPE;
	private boolean newUser;
	
//	private SystemAccessBean(String un, String pwd){	
//		id=1;
//		userName="Sasa";
//		password="sasa";
//		eMail="throwthis@gmail.com";
//		userType=UserTypes.ADMIN;
//	}
	
	public SystemAccessBean() {}
	
	public static SystemAccessBean getInstance(String un, String pwd){
		SystemAccessBean instance = null;
		for(IBean sab:DAOtundra.getInstance().getAllBeans(new SystemAccessBean())){
			if ( ((SystemAccessBean)sab).getUserName().equals(un)  )
				if ( ((SystemAccessBean)sab).getPassword().equals(pwd) ){
					instance = (SystemAccessBean)sab;
					break;
				}else return null;
		}
		return instance;
	}
	
	public static boolean isUNameUnique(String un){
		if (null==un || un.equals("") || un.length()<3){
			return false;
		}
		List<IBean> userList = DAOtundra.getInstance().getAllBeans(new SystemAccessBean());
		for (IBean sab:userList)
			if ( un.equals( ((SystemAccessBean)sab).getUserName() ) )
				return false;
		return true;
	}
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public short getUserType() {
		return (short)this.userType.getValue();
	}

	public void setUserType(short userType) {
		if (null == (this.userType=UserTypes.get(userType)))
			this.userType=UserTypes.EXTERN;
	}

	public void setUserType(UserTypes userType) {
			this.userType=userType;
	}
	public boolean isNewUser() {
		return newUser;
	}
	public void setNewUser(boolean newUser) {
		this.newUser = newUser;
	}
	public String geteMail() {
		return eMail;
	}
	public void seteMail(String eMail) {
		this.eMail = eMail;
	}
	@Override
	public short getClassId() {
		return TundraConstants.SYSTEM_ACCESS_BEAN;
	}
}
